package mao.exaimnation.meituan;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.logging.Filter;

/**
 * @author Totoro
 * @date 2020/8/29
 * @explain:
 */
public class Main3 {

    public static void main(String[] args) throws FileNotFoundException {
        Scanner scanner = new Scanner(System.in);
        File file =  new File("aa");

        Scanner scanner1 = new Scanner(new FileInputStream(file));
        //List<Integer> list;
        while (scanner.hasNext()) {
            int m = scanner.nextInt();
            int n = scanner.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = scanner.nextInt();
            }
            int pre;
            int res = 0;
            for (int l = 1; l <= m; l++) {
                for (int r = l; r <= m; r++) {
                    pre = Integer.MIN_VALUE;
                    boolean flag = true;
                    for (int i = 0; i < arr.length; i++) {
                        if ((arr[i]>0 && arr[i]<l) || (arr[i]>r && arr[i]<m+1 ) ){
                            if (arr[i] >= pre){
                                pre =  arr[i];
                            }else {
                                flag = false;
                                break;
                            }
                        }
                    }
                    if (flag) res++;
                }
            }
            System.out.println(res);
        }

    }
}
